#ifndef __DANIEL_MYHASH_H__
#define __DANIEL_MYHASH_H__

#include <openssl/md5.h>
#include <openssl/sha.h>
#include <memory>

namespace daniel
{
    class MyHash
    {
    public:
        using ptr=std::shared_ptr<MyHash>;
        enum HashType{MD5=0,SHA1,SHA224,SHA256,SHA384,SHA512};
        MyHash(HashType type);
        ~MyHash();
        void init();
        void update(void* data, size_t len);
        void final();
        std::string toHashString();
        void hash(const unsigned char* d, size_t n);
    private:
        //考虑使用联合体进行优化
        HashType m_type;
        union
        {
            MD5_CTX* m_MD5_CTX;
            SHA_CTX* m_SHA1_CTX;
            SHA256_CTX* m_SHA224_CTX;
            SHA256_CTX* m_SHA256_CTX;
            SHA512_CTX* m_SHA384_CTX;
            SHA512_CTX* m_SHA512_CTX; 
        } m_ctx;
        unsigned char* m_md;
    };
} // namespace daniel

#endif